package com.rpgfw.scene;

import com.rpgfw.graphics.DrawGraphics;
import com.rpgfw.graphics.PixelGraphics;

import java.awt.*;

/*
* 场景，包含entity
* */
public class Scene implements DrawGraphics {
    Color pixel[][];
    Color initCl=new Color(255,255, 255);
    final PixelGraphics graphics=new PixelGraphics(this);

    //scene的位置
    Point location=new Point(0,0);
    /*
    * 给定长宽（x，y方向上的格子数量）以初始化scene
    * */
    public Scene(int width,int height){
        this.init(width,height,this.initCl);
    }
    /*
     * 给定长宽（x，y方向上的格子数量）和每个格子的长宽（像素）以及格子初始化颜色以初始化scene
     * */
    public Scene(int width,int height,Color initCl){
        this.init(width,height,initCl);
    }
    /*
    * 初始化
    * */
    void init(int width,int height,Color initCl){
        //初始化颜色更新
        this.initCl=new Color(initCl.getRGB());
        //初始化格子
        this.pixel=new Color[height][width];
        for(int i=0;i<height;i++){
            for(int j=0;j<width;j++){
                this.pixel[i][j]=new Color(initCl.getRGB());
            }
        }
        //注册graphics
        //this.graphics=new PixelGraphics(this);
    }
    public void setLocation(int x,int y){
        this.location.setLocation(x,y);
    }
    public Point getLocation(){
        return this.location;
    }
    public int getX(){
        return (int)this.location.getX();
    }
    public int getY(){
        return (int)this.location.getY();
    }

    @Override
    public void drawDot(int x,int y){
        if(y<this.pixel.length&&x<this.pixel[0].length&&y>=0&&x>=0) {
            this.pixel[y][x] = this.graphics.getColor();
            //System.out.println("dot "+x+" "+y+" cl:"+this.pixel[y][x]);
        }
    }
    @Override
    public void changeColor(Color color){

    }


    //下面是getter和setter

    /*
    * graphics
    * */
    public PixelGraphics getPixelGraphics(){
        return this.graphics;
    }
    public Color getPixel(int x,int y){
        return new Color(this.pixel[y][x].getRGB());
    }
    public int getWidth(){
        return this.pixel[0].length;
    }
    public int getHeight(){
        return  this.pixel.length;
    }
    public Color getInitCl(){
        return new Color(this.initCl.getRGB());
    }
}
